//
//  SPDataCAreaHeaderFooterView.m
//  panzer
//
//  Created by 还带大道 on 2018/10/24.
//  Copyright © 2018年 还带大道. All rights reserved.
//

#import "SPDataCAreaHeaderFooterView.h"
#import "SPCommon.h"
#import "SPLiveDetailAreaCollectionViewCell.h"
#import "SPDataCModel.h"

@interface SPDataCAreaHeaderFooterView()<UICollectionViewDataSource,UICollectionViewDelegate>
@property (weak, nonatomic) IBOutlet UIView *bgView;
@property (weak, nonatomic) IBOutlet UICollectionView *collectionView;

@end

@implementation SPDataCAreaHeaderFooterView


- (void)awakeFromNib
{
    [super awakeFromNib];
    [self setupShadow];
    
    UICollectionViewFlowLayout *flowLayout = (UICollectionViewFlowLayout *)self.collectionView.collectionViewLayout;
    
    CGFloat width = 60;
    CGFloat height = 30;
    flowLayout.itemSize = CGSizeMake(width, height);
    // 设置最小行间距
    flowLayout.minimumLineSpacing = 15;
    // 设置最小列间距
    flowLayout.minimumInteritemSpacing = 0;
    flowLayout.sectionInset = UIEdgeInsetsMake(15, 0, 15, 0);
    
    [self.collectionView registerNib:[UINib nibWithNibName:NSStringFromClass([SPLiveDetailAreaCollectionViewCell class]) bundle:nil] forCellWithReuseIdentifier:NSStringFromClass([SPLiveDetailAreaCollectionViewCell class])];
}


+ (instancetype)shareHeaderView
{
    return [[NSBundle mainBundle] loadNibNamed:NSStringFromClass([self class]) owner:nil options:nil].lastObject;
}


- (void)setupShadow
{
    _bgView.layer.shadowColor = RZ_COLOR_ALPHA(201, 201, 201, 0.37).CGColor;
    _bgView.layer.cornerRadius = 5;
    _bgView.layer.shadowOffset = CGSizeMake(0,1);//shadowOffset阴影偏移,x向右偏移，y向下偏移，默认(0, -3)
    _bgView.layer.shadowOpacity = 1;//阴影透明度，默认0
    _bgView.layer.shadowRadius = 4;//阴影半径，默认3
}


- (void)layoutSubviews
{
    [super layoutSubviews];
    [self.collectionView layoutIfNeeded];
    UICollectionViewFlowLayout *flowLayout = (UICollectionViewFlowLayout *)self.collectionView.collectionViewLayout;
    CGSize size = flowLayout.itemSize;
    CGFloat width = self.collectionView.width / 4;
    size.width = width;
    flowLayout.itemSize = size;
    
    CGFloat height = flowLayout.collectionViewContentSize.height+10;
    !self.refreshBlock?:self.refreshBlock(height);
}



- (void)setCitys:(NSArray<SPCityDataModel *> *)citys
{
    _citys = citys;
    [self.collectionView reloadData];
}


#pragma mark <UICollectionViewDataSource>

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 1;
}


- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return _citys.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    SPLiveDetailAreaCollectionViewCell *cell =  [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([SPLiveDetailAreaCollectionViewCell class]) forIndexPath:indexPath];
    cell.title.text = _citys[indexPath.row].name;
    cell.count.text = [NSString stringWithFormat:@"%ld",_citys[indexPath.row].num];
    cell.title.textColor = RZ_COLOR(155, 155, 155);
    cell.title.font = [UIFont systemFontOfSize:10];
    cell.count.textColor = RZ_COLOR(74, 74, 74);
    cell.count.font = [UIFont systemFontOfSize:12];
    cell.unit.hidden = YES;
    cell.count_centerX_offset.constant = 0;
    return cell;
}




- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    RZLog(@"collectionView--%ld",(long)indexPath.item);
}


@end

